from rest_framework import serializers

from areas.models import Area


class AreaInfoSerializer(serializers.ModelSerializer):
    """查询省份的序列化器"""

    class Meta:
        model = Area
        fields = ['id', 'name']


class SubAreaInfoSerializer(serializers.ModelSerializer):
    """查询省份的序列化器"""
    #  自动调用自己　自关联
    #  subs = areas_set这个属性
    subs = AreaInfoSerializer(many=True, read_only=True)

    class Meta:
        model = Area
        fields = ['id', 'name', 'subs']
